iT邦幫忙

2021 iThome 鐵人賽

DAY 23
1

進場大修的一天,拿了包高血壓藥。在候診間持續debug人生XD
依舊先上個進度圖:

+ mkdir -p /sysroot/sys /sysroot/proc /sysroot/dev
+ mount -o bind /sys /sysroot/sys
+ mount -o bind /proc /sysroot/proc
+ mount -o bind /dev /sysroot/dev
+ '[' -n  ]
+ apk add --root /sysroot --repository /main --initramfs-diskless-boot --progress --no-network --clean-protected alpine-base openssl
(1/21) Installing musl (1.2.2-r6)
(2/21) Installing busybox (1.34.0-r5)
Executing busybox-1.34.0-r5.post-install
(3/21) Installing alpine-baselayout (3.2.0-r18)
Executing alpine-baselayout-3.2.0-r18.pre-install
Executing alpine-baselayout-3.2.0-r18.post-install
(4/21) Installing busybox-ifupdown (1.34.0-r5)
(5/21) Installing openrc (0.44.5-r0)
Executing openrc-0.44.5-r0.post-install
(6/21) Installing alpine-conf (3.12.0-r0)
(7/21) Installing libcrypto3 (3.0.0-r2)
(8/21) Installing libssl3 (3.0.0-r2)
(9/21) Installing ca-certificates-bundle (20191127-r6)
(10/21) Installing libretls (3.3.4-r1)
(11/21) Installing ssl_client (1.34.0-r5)
(12/21) Installing zlib (1.2.11-r3)
(13/21) Installing apk-tools (2.12.7-r1)
(14/21) Installing busybox-suid (1.34.0-r5)
(15/21) Installing busybox-initscripts (3.3-r1)
Executing busybox-initscripts-3.3-r1.post-install
(16/21) Installing scanelf (1.3.3-r0)
(17/21) Installing musl-utils (1.2.2-r6)
(18/21) Installing libc-utils (0.7.2-r3)
(19/21) Installing alpine-keys (2.3-r1)
(20/21) Installing alpine-base (3.15.0_alpha20210804-r0)
(21/21) Installing openssl (3.0.0-r2)
Executing busybox-1.34.0-r5.trigger
OK: 8 MiB in 21 packages
+ umount /sysroot/sys /sysroot/proc /sysroot/dev
+ eend 0
+ local msg
+ '[' 0 '=' 0 ]
+ echo 'Installing packages to root filesystem: ok.'
[    6.516422] Installing packages to root filesystem: ok.
......
+ '[' '!' -x /sysroot/init ]
+ '[' no '!=' no ]
+ echo '/init not found in new root. Launching emergency recovery shell'
/init not found in new root. Launching emergency recovery shell
+ echo 'Type exit to continue boot.'
Type exit to continue boot.
+ /bin/busybox sh
sh: can't access tty; job control turned off
/ # 

衝到apk組出「半殘的」rootfs,這時是個怪異的狀況,主要是在新rootfs中,/init不存在,照理來說他是openrc的symbolic link,這點在sysmted也是類似的設計,但是土砲的結果 — —

/sysroot # ln -s ./sbin/openrc ./init
/sysroot # chroot . /init
 * Caching service dependencies ...
 [ ok ]
grep: /proc/filesystems: No such file or directory
 * You are attempting to run an openrc service on a
 * system which openrc did not boot.
 * You may be inside a chroot or you may have used
 * another initialization system to boot this system.
 * In this situation, you will get unpredictable results!
 * If you really want to do this, issue the following command:
 * touch /run/openrc/softlevel
 * ERROR: devfs failed to start
grep: /proc/filesystems: No such file or directory

似乎還是不理想QQ

然而走到這步,其實已經是debug過一輪狀況。首先,還是要感謝Linux系統程式工程師救火的MVP— — QEMU。在我第一輪把mmap2 syscall num fix過的libc推進去重編後,initramfs中的apk裝東西、跟search時都會segfault掉。

然而我在使用幾篇的小技巧,:bootstrap riscv32 aports時,可以在 bootstrap.sh 中把 sysroot 留住(加上 abuild -r -R),原本我只是想要繼續用qemu linux-user mode來比較好debug,但是卻發現竟然是好的!?

這下就有趣了,老實說還是懶得直接看code,想直接對一次壞掉跟好的粗略差別,於是我就開啟了系統呼叫的tracer來看: qemu-riscv32 -strace -L /path/to/extracted ./sbin/apk -X /home/ruinland/packages/main -U --arch riscv32 --allow-untrusted search alpine 2>&1 | failed_apk.log

跟可以正常運作的版本一比較,發現了這道:
504224 openat(5,"ruinland-6151dfc0.rsa.pub",O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 7

あややや,竟然是拿來bootstrap world的key沒塞進initramfs的/etc/apk/keys惹得禍。在前後我們還發現了 Unknown syscall 62 這點,不過這個真的蠻詭異的、因為llseek在qemu的source裡面就是62號、musl porting我也是這樣填,可能還得找時間驗證這是怎麼拐錯的。

下一篇的進度,應該會是想辦法看看ARM那邊衝到能開機時,到底裝了哪些套件、有什麼是我riscv32 world還沒bootstrap到的。


上一篇
Alpine Linux Porting (一點十?)
下一篇
Alpine Linux Porting (1.99) ES LEBT !!!
系列文
Port Alpine Linux to open source RISC-V platform30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
高魁良
iT邦新手 1 級 ‧ 2021-10-02 21:23:03

保重啊~

我要留言

立即登入留言